Prev Next |
The value of the Treelist field is very similar to the value of the Checklist and Multilist field in that it is a pipe-separated list of IDs of the selected items.
The expression below:
<xsl:value-of select="sc:fld('My Treelist', .)"/>
would output something similar to this:
{B9F4A9B3-FAD2-4D79-9F97-6E66D1FF33C4}|{E473B7A4-6956-4319-B69E-147D91223E4A}
which means that an item with the ID
{B9F4A9B3-FAD2-4D79-9F97-6E66D1FF33C4}
and items with ID
{E473B7A4-6956-4319-B69E-147D91223E4A}
were selected in the treelist field.
You can then parse the string to retrieve individual IDs, get the items identified by the IDs and process them according to the needs of your application. The example below prints "Title" fields of selected items:
<xsl:template match="*" mode="main">
<xsl:variable name="ids" select="concat(sc:fld('My Treelist',.),'|')"/>
<xsl:call-template name="PrintTitles">
<xsl:with-param name="ids" select="$ids"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="PrintTitles">
<xsl:param name="ids"/>
<xsl:if test="$ids">
<xsl:variable name="itm_id" select="substring-before($ids, '|')"/>
<xsl:if test="$itm_id">
<xsl:variable name="itm" select="sc:item($itm_id,.)"/>
<xsl:value-of select="sc:fld('Title', $itm)"/>
<br/>
</xsl:if>
<xsl:call-template name="PrintTitles">
<xsl:with-param name="ids" select="substring-after($ids, '|')"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
Sample Content Editor input:
Corresponding output in Preview mode:
Prev Next